Skip to content

Commit

Permalink
Added Audio and Pre-trained Large model
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghaoddd committed Oct 24, 2022
1 parent dacf535 commit 1789c77
Show file tree
Hide file tree
Showing 75 changed files with 79 additions and 22 deletions.
Binary file modified FYP/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file added FYP/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file modified FYP/__pycache__/settings.cpython-37.pyc
Binary file not shown.
Binary file added FYP/__pycache__/settings.cpython-39.pyc
Binary file not shown.
Binary file modified FYP/__pycache__/urls.cpython-37.pyc
Binary file not shown.
Binary file added FYP/__pycache__/urls.cpython-39.pyc
Binary file not shown.
Binary file modified FYP/__pycache__/wsgi.cpython-37.pyc
Binary file not shown.
Binary file added FYP/__pycache__/wsgi.cpython-39.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions OFA/OFA
Submodule OFA added at 7f7e6b
Binary file modified OFA/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file added OFA/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file modified OFA/__pycache__/admin.cpython-37.pyc
Binary file not shown.
Binary file added OFA/__pycache__/admin.cpython-39.pyc
Binary file not shown.
Binary file modified OFA/__pycache__/apps.cpython-37.pyc
Binary file not shown.
Binary file added OFA/__pycache__/apps.cpython-39.pyc
Binary file not shown.
Binary file modified OFA/__pycache__/forms.cpython-37.pyc
Binary file not shown.
Binary file added OFA/__pycache__/forms.cpython-39.pyc
Binary file not shown.
Binary file modified OFA/__pycache__/models.cpython-37.pyc
Binary file not shown.
Binary file added OFA/__pycache__/models.cpython-39.pyc
Binary file not shown.
Binary file modified OFA/__pycache__/urls.cpython-37.pyc
Binary file not shown.
Binary file added OFA/__pycache__/urls.cpython-39.pyc
Binary file not shown.
Binary file modified OFA/__pycache__/views.cpython-37.pyc
Binary file not shown.
Binary file added OFA/__pycache__/views.cpython-39.pyc
Binary file not shown.
Binary file added OFA/audio.mp3
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions OFA/fairseq
Submodule fairseq added at 027219
Binary file removed OFA/media/Empty_Image.png
Binary file not shown.
Binary file removed OFA/media/Screenshot 2022-10-17 162715.png
Binary file not shown.
18 changes: 18 additions & 0 deletions OFA/migrations/0004_alter_ofaimage_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.16 on 2022-10-24 03:07

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('OFA', '0003_alter_ofaimage_image'),
]

operations = [
migrations.AlterField(
model_name='ofaimage',
name='image',
field=models.ImageField(upload_to='OFA\\static'),
),
]
Binary file modified OFA/migrations/__pycache__/0001_initial.cpython-37.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified OFA/migrations/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file added OFA/migrations/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion OFA/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from django.db import models
class OFAImage(models.Model):
image = models.ImageField(upload_to='')
image = models.ImageField(upload_to='OFA\static')
1 change: 1 addition & 0 deletions OFA/ofa_image-caption_coco_large_en
Submodule ofa_image-caption_coco_large_en added at 6bf8ca
Binary file removed OFA/static/Screenshot 2022-10-14 195905.png
Binary file not shown.
Binary file removed OFA/static/Screenshot 2022-10-14 195905_OcCkF3W.png
Binary file not shown.
Binary file added OFA/static/face.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion OFA/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
urlpatterns = [
path('', views.index, name='index'),
path('About', views.about, name='about'),
path('Model', views.model, name='model'),
path('Model', views.model, name='model')
]

39 changes: 32 additions & 7 deletions OFA/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
import os
from datetime import datetime


# better accuracy but slower
# img_captioning = pipeline(
# Tasks.image_captioning,
# model='ofa_image-caption_coco_large_en')
# model='OFA/ofa_image-caption_coco_large_en')

# lower accuracy but very fast
img_captioning = pipeline(
Tasks.image_captioning,
model='damo/ofa_image-caption_coco_distilled_en')

# result = img_captioning({'image': 'https://farm9.staticflickr.com/8044/8145592155_4a3e2e1747_z.jpg'})
# print(result[OutputKeys.CAPTION]) # 'a bunch of donuts on a wooden board with popsicle sticks'

Expand All @@ -32,14 +35,20 @@ def index(request):
def about(request):
return render(request, 'about.html')

# @csrf_exempt
# def model(request):
# return render(request, 'OFA.html')

caption = "No Caption!"
@csrf_exempt
def model(request):
start_time = datetime.now()
if request.method == 'POST':
if request.method == 'POST':

# Remove all old images
directory = "OFA/static"
files_in_directory = os.listdir(directory)
for file in files_in_directory:
path_to_file = os.path.join(directory, file)
os.remove(path_to_file)

# Image Display
form = OFAImageForm(request.POST, request.FILES)
if form.is_valid():
Expand All @@ -48,10 +57,21 @@ def model(request):

# OFA Image Caption from pre-trained
result = img_captioning({'image': img_object.image.name})
global caption
caption = result[OutputKeys.CAPTION][0]

# Save audio file
engine = pyttsx3.init()
engine.save_to_file(caption, 'OFA/audio.mp3')
engine.runAndWait()

# timer
end_time = datetime.now()
time_lapsed = end_time - start_time

# format time
t = str(round(time_lapsed.total_seconds(),1))+'s'

# data will send to frontend
context = {
'form': form,
Expand All @@ -62,10 +82,14 @@ def model(request):
return render(request, 'OFA.html', context)
else:
form = OFAImageForm()

# timer
end_time = datetime.now()
time_lapsed = end_time - start_time

# format time
t = str(round(time_lapsed.total_seconds(),1))+'s'

# data will send to frontend
context = {
'form' : form,
Expand All @@ -87,4 +111,5 @@ def caption1(request):
'caption': result[OutputKeys.CAPTION]
}
return render(request, 'OFA.html', context)
"""
"""

1 change: 1 addition & 0 deletions ReadMe.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
python -m venv venv
.\venv\Scripts\activate
pip install "modelscope[nlp]==0.4.7" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html
pip install git+https://github.com/nateshmbhat/pyttsx3
pip install -r requirements.txt
python manage.py makemigrations
python manage.py migrate
Expand Down
Binary file removed child-in-car-scaled_Soac6UM.jpg
Binary file not shown.
Binary file modified db.sqlite3
Binary file not shown.
23 changes: 16 additions & 7 deletions templates/OFA.html
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
</nav>
</div></header>
<center><h4>OFA (pre-trained)</h4>
<div style="width: 100%; overflow: hidden;">
<div style="width: 70%; overflow: hidden;">

<form method="POST" action ="Model" enctype="multipart/form-data">
{% comment %} <p>Please select your OFA model: </p>
Expand All @@ -211,7 +211,7 @@
<label for="OFALarge">Large</label>
<input type="radio" id="OFATiny" name="OFA" value="OFA_Tiny">
<label for="OFATiny">Tiny</label><br> {% endcomment %}
<div style="width: 50%; float: left;">
<div style="width: 40%; float: left;">
{% block content %}
{% csrf_token %}
<br>
Expand All @@ -227,7 +227,7 @@
<br>
<img id="output" src = " " />
<span>&times;</span>
<input type="file" name="image" onchange="loadFile(event)" >
<input type="file" accept="image/*" name="image" onchange="loadFile(event)" >
<br><br>
</div>
<br>
Expand All @@ -237,13 +237,22 @@
</div>
</div>

<div style="width: 50%; float: right;">
<div style="width: 50%; float: right;">
{% if img_obj %}
<img src="{{ img_obj.image.url}}" alt="connect" style="max-height:300px">
{% endif %}
{% endblock content %}
<p><strong>Caption: </strong> {{result}}</p>
<p><strong>Timing: </strong> {{time_lapsed}}</p>
{% endblock content %}
<br>
<small>processing: {{time_lapsed}}</small>
<br>
<br>
<div>
<audio controls preload="none">
<source src="audio.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<p><strong>Caption: </strong> {{result}}</p>
</div>
</div>
</form>
</div>
Expand Down
6 changes: 3 additions & 3 deletions templates/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
<body class="u-body u-xl-mode" data-lang="en">
<header class="u-clearfix u-header u-header" id="sec-164b">
<div class="u-clearfix u-sheet u-sheet-1">
<a href="Home.html" class="u-image u-logo u-image-1" data-image-width="870" data-image-height="870">
<a href="{% load static %}" class="u-image u-logo u-image-1" data-image-width="870" data-image-height="870">
<img src="images/UOW.png" class="u-logo-image u-logo-image-1">
</a>
<a href="Home.html" class="u-image u-logo u-image-2" data-image-width="200" data-image-height="200">
<a href="{% load static %}" class="u-image u-logo u-image-2" data-image-width="200" data-image-height="200">
<img src="images/1663124232782.jpg" class="u-logo-image u-logo-image-2">
</a>
<nav class="u-menu u-menu-dropdown u-offcanvas u-menu-1">
Expand All @@ -63,7 +63,7 @@
<div class="u-nav-container">
<ul class="u-nav u-unstyled u-nav-1"><li class="u-nav-item"><a class="u-button-style u-nav-link u-text-active-palette-1-base u-text-hover-palette-2-base" href="{% url 'index' %}" style="padding: 10px 14px;">Home</a>
</li><li class="u-nav-item"><a class="u-button-style u-nav-link u-text-active-palette-1-base u-text-hover-palette-2-base" href="{% url 'about' %}" style="padding: 10px 14px;">About</a>
</li><li class="u-nav-item"><a class="u-button-style u-nav-link u-text-active-palette-1-base u-text-hover-palette-2-base" href="{% url 'model' %}" target="_blank" style="padding: 10px 14px;">Model</a>
</li><li class="u-nav-item"><a class="u-button-style u-nav-link u-text-active-palette-1-base u-text-hover-palette-2-base" href="{% url 'model' %}" style="padding: 10px 14px;">Model</a>
</li></ul>
</div>
<div class="u-nav-container-collapse">
Expand Down
6 changes: 3 additions & 3 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="description" content="">
<title>Home</title>
<link rel="stylesheet" href="nicepage.css" media="screen">
<link rel="stylesheet" href="Home.css" media="screen">
<link rel="stylesheet" href="Home.css" media="screen">
<script class="u-script" type="text/javascript" src="jquery.js" defer=""></script>
<script class="u-script" type="text/javascript" src="nicepage.js" defer=""></script>
<meta name="generator" content="Nicepage 4.19.3, nicepage.com">
Expand Down Expand Up @@ -47,7 +47,7 @@
<div class="u-nav-container">
<ul class="u-nav u-unstyled u-nav-1"><li class="u-nav-item"><a class="u-button-style u-nav-link u-text-active-palette-1-base u-text-hover-palette-2-base" href="{% url 'index' %}" style="padding: 10px 14px;">Home</a>
</li><li class="u-nav-item"><a class="u-button-style u-nav-link u-text-active-palette-1-base u-text-hover-palette-2-base" href="{% url 'about' %}" style="padding: 10px 14px;">About</a>
</li><li class="u-nav-item"><a class="u-button-style u-nav-link u-text-active-palette-1-base u-text-hover-palette-2-base" href="{% url 'model' %}" target="_blank" style="padding: 10px 14px;">Model</a>
</li><li class="u-nav-item"><a class="u-button-style u-nav-link u-text-active-palette-1-base u-text-hover-palette-2-base" href="{% url 'model' %}" style="padding: 10px 14px;">Model</a>
</li></ul>
</div>
<div class="u-nav-container-collapse">
Expand Down Expand Up @@ -107,7 +107,7 @@ <h2 class="u-custom-font u-font-montserrat u-text u-text-1">The Majoriy of the p
<div class="u-align-center u-container-style u-layout-cell u-size-30 u-layout-cell-2">
<div class="u-container-layout u-container-layout-2">
<h2 class="u-text u-text-default u-text-2"> Our AI-Powered model is capbe to generate comprehensive sentence from image</h2>
<a href="{% url 'model' %}" class="u-btn u-button-style u-hover-black u-palette-1-base u-btn-1" target="_blank">try it now</a>
<a href="{% url 'model' %}" class="u-btn u-button-style u-hover-black u-palette-1-base u-btn-1" >try it now</a>
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions templates/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{result}}
Binary file modified text2audio/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file added text2audio/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file modified text2audio/__pycache__/admin.cpython-37.pyc
Binary file not shown.
Binary file added text2audio/__pycache__/admin.cpython-39.pyc
Binary file not shown.
Binary file modified text2audio/__pycache__/apps.cpython-37.pyc
Binary file not shown.
Binary file added text2audio/__pycache__/apps.cpython-39.pyc
Binary file not shown.
Binary file modified text2audio/__pycache__/forms.cpython-37.pyc
Binary file not shown.
Binary file added text2audio/__pycache__/forms.cpython-39.pyc
Binary file not shown.
Binary file modified text2audio/__pycache__/models.cpython-37.pyc
Binary file not shown.
Binary file added text2audio/__pycache__/models.cpython-39.pyc
Binary file not shown.
Binary file modified text2audio/__pycache__/urls.cpython-37.pyc
Binary file not shown.
Binary file added text2audio/__pycache__/urls.cpython-39.pyc
Binary file not shown.
Binary file modified text2audio/__pycache__/views.cpython-37.pyc
Binary file not shown.
Binary file added text2audio/__pycache__/views.cpython-39.pyc
Binary file not shown.
Binary file modified text2audio/migrations/__pycache__/0001_initial.cpython-37.pyc
Binary file not shown.
Binary file not shown.
Binary file modified text2audio/migrations/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file not shown.

0 comments on commit 1789c77

Please sign in to comment.