Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,12 @@ import torch
|
|
| 4 |
from PIL import Image
|
| 5 |
from transformers import AutoModel, AutoTokenizer
|
| 6 |
import spaces
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
device="cuda"
|
| 9 |
|
|
@@ -16,6 +22,23 @@ model.eval()
|
|
| 16 |
# Define a function to generate a response
|
| 17 |
@spaces.GPU
|
| 18 |
def generate_response(image, question):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
msgs = [{'role': 'user', 'content': question}]
|
| 20 |
res = model.chat(
|
| 21 |
image=image,
|
|
@@ -33,11 +56,8 @@ def generate_response(image, question):
|
|
| 33 |
# Create the footer with links
|
| 34 |
footer = """
|
| 35 |
<div style="text-align: center; margin-top: 20px;">
|
| 36 |
-
<a href="https://www.linkedin.com/in/pejman-ebrahimi-4a60151a7/" target="_blank">LinkedIn</a> |
|
| 37 |
-
<a href="https://github.com/arad1367/Visual_QA_MiniCPM-Llama3-V-2_5_GradioApp" target="_blank">GitHub</a> |
|
| 38 |
-
<a href="https://arad1367.pythonanywhere.com/" target="_blank">Live demo of my PhD defense</a>
|
| 39 |
<br>
|
| 40 |
-
Made with 💖 by
|
| 41 |
</div>
|
| 42 |
"""
|
| 43 |
|
|
@@ -52,4 +72,4 @@ with gr.Blocks(theme='abidlabs/dracula_revamped') as demo:
|
|
| 52 |
gr.HTML(footer)
|
| 53 |
|
| 54 |
# Launch the app
|
| 55 |
-
demo.launch(debug=True)
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
from transformers import AutoModel, AutoTokenizer
|
| 6 |
import spaces
|
| 7 |
+
from googletrans import Translator
|
| 8 |
+
|
| 9 |
+
translator = Translator()
|
| 10 |
+
|
| 11 |
+
def translate_to_english(text):
|
| 12 |
+
return translator.translate(text, src='zh-cn', dest='en').text
|
| 13 |
|
| 14 |
device="cuda"
|
| 15 |
|
|
|
|
| 22 |
# Define a function to generate a response
|
| 23 |
@spaces.GPU
|
| 24 |
def generate_response(image, question):
|
| 25 |
+
msgs = [{'role': 'user', 'content': question}]
|
| 26 |
+
res = model.chat(
|
| 27 |
+
image=image,
|
| 28 |
+
msgs=msgs,
|
| 29 |
+
tokenizer=tokenizer,
|
| 30 |
+
sampling=True,
|
| 31 |
+
temperature=0.7,
|
| 32 |
+
stream=True
|
| 33 |
+
)
|
| 34 |
+
generated_text = "".join(res)
|
| 35 |
+
|
| 36 |
+
# Translate to English
|
| 37 |
+
translated_text = translate_to_english(generated_text)
|
| 38 |
+
|
| 39 |
+
return translated_text
|
| 40 |
+
|
| 41 |
+
def generate_response_old(image, question):
|
| 42 |
msgs = [{'role': 'user', 'content': question}]
|
| 43 |
res = model.chat(
|
| 44 |
image=image,
|
|
|
|
| 56 |
# Create the footer with links
|
| 57 |
footer = """
|
| 58 |
<div style="text-align: center; margin-top: 20px;">
|
|
|
|
|
|
|
|
|
|
| 59 |
<br>
|
| 60 |
+
Made with 💖 by CodeMonkeyXL
|
| 61 |
</div>
|
| 62 |
"""
|
| 63 |
|
|
|
|
| 72 |
gr.HTML(footer)
|
| 73 |
|
| 74 |
# Launch the app
|
| 75 |
+
demo.launch(debug=True,show_api=True)
|