Update app.py
Browse files
app.py
CHANGED
@@ -3,14 +3,9 @@ from gradio_client import Client, handle_file
|
|
3 |
from huggingface_hub import InferenceClient
|
4 |
|
5 |
moondream_client = Client("vikhyatk/moondream2")
|
6 |
-
|
7 |
qwq_client = InferenceClient("Qwen/QwQ-32B-Preview")
|
8 |
|
9 |
-
history = []
|
10 |
-
|
11 |
def describe_image(image, user_message):
|
12 |
-
global history
|
13 |
-
|
14 |
result = moondream_client.predict(
|
15 |
img=handle_file(image),
|
16 |
prompt="Describe this image.",
|
@@ -19,12 +14,8 @@ def describe_image(image, user_message):
|
|
19 |
|
20 |
description = result
|
21 |
|
22 |
-
history.append(f"User: {user_message}")
|
23 |
-
history.append(f"Assistant: {description}")
|
24 |
-
|
25 |
-
full_conversation = "\n".join(history)
|
26 |
qwq_result = qwq_client.chat_completion(
|
27 |
-
messages=[{"role": "user", "content":
|
28 |
max_tokens=512,
|
29 |
temperature=0.7,
|
30 |
top_p=0.95
|
@@ -33,15 +24,11 @@ def describe_image(image, user_message):
|
|
33 |
return description + "\n\nAssistant: " + qwq_result['choices'][0]['message']['content']
|
34 |
|
35 |
def chat_or_image(image, user_message):
|
36 |
-
global history
|
37 |
-
|
38 |
if image:
|
39 |
return describe_image(image, user_message)
|
40 |
else:
|
41 |
-
history.append(f"User: {user_message}")
|
42 |
-
full_conversation = "\n".join(history)
|
43 |
qwq_result = qwq_client.chat_completion(
|
44 |
-
messages=[{"role": "user", "content":
|
45 |
max_tokens=512,
|
46 |
temperature=0.7,
|
47 |
top_p=0.95
|
@@ -58,4 +45,4 @@ demo = gr.Interface(
|
|
58 |
)
|
59 |
|
60 |
if __name__ == "__main__":
|
61 |
-
demo.launch(show_error=True)
|
|
|
3 |
from huggingface_hub import InferenceClient
|
4 |
|
5 |
moondream_client = Client("vikhyatk/moondream2")
|
|
|
6 |
qwq_client = InferenceClient("Qwen/QwQ-32B-Preview")
|
7 |
|
|
|
|
|
8 |
def describe_image(image, user_message):
|
|
|
|
|
9 |
result = moondream_client.predict(
|
10 |
img=handle_file(image),
|
11 |
prompt="Describe this image.",
|
|
|
14 |
|
15 |
description = result
|
16 |
|
|
|
|
|
|
|
|
|
17 |
qwq_result = qwq_client.chat_completion(
|
18 |
+
messages=[{"role": "user", "content": user_message}],
|
19 |
max_tokens=512,
|
20 |
temperature=0.7,
|
21 |
top_p=0.95
|
|
|
24 |
return description + "\n\nAssistant: " + qwq_result['choices'][0]['message']['content']
|
25 |
|
26 |
def chat_or_image(image, user_message):
|
|
|
|
|
27 |
if image:
|
28 |
return describe_image(image, user_message)
|
29 |
else:
|
|
|
|
|
30 |
qwq_result = qwq_client.chat_completion(
|
31 |
+
messages=[{"role": "user", "content": user_message}],
|
32 |
max_tokens=512,
|
33 |
temperature=0.7,
|
34 |
top_p=0.95
|
|
|
45 |
)
|
46 |
|
47 |
if __name__ == "__main__":
|
48 |
+
demo.launch(show_error=True)
|