Spaces:
Runtime error
Runtime error
jordigonzm
commited on
Commit
•
e00a1e0
1
Parent(s):
aacf9f2
Update app.py
Browse files
app.py
CHANGED
@@ -2,8 +2,7 @@ import os
|
|
2 |
import gradio as gr
|
3 |
from http import HTTPStatus
|
4 |
import dashscope
|
5 |
-
from
|
6 |
-
from dashscope.api_entities.dashscope_response import Role
|
7 |
from typing import List, Optional, Tuple, Dict
|
8 |
from urllib.error import HTTPError
|
9 |
|
@@ -46,23 +45,14 @@ def model_chat(query: Optional[str], history: Optional[History], system: str
|
|
46 |
history = []
|
47 |
messages = history_to_messages(history, system)
|
48 |
messages.append({'role': Role.USER, 'content': query})
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
role = response.output.choices[0].message.role
|
58 |
-
response = response.output.choices[0].message.content
|
59 |
-
system, history = messages_to_history(messages + [{'role': role, 'content': response}])
|
60 |
-
yield '', history, system
|
61 |
-
else:
|
62 |
-
raise ValueError('Request id: %s, Status code: %s, error code: %s, error message: %s' % (
|
63 |
-
response.request_id, response.status_code,
|
64 |
-
response.code, response.message
|
65 |
-
))
|
66 |
|
67 |
with gr.Blocks() as demo:
|
68 |
with gr.TabBar():
|
|
|
2 |
import gradio as gr
|
3 |
from http import HTTPStatus
|
4 |
import dashscope
|
5 |
+
from transformers import pipeline
|
|
|
6 |
from typing import List, Optional, Tuple, Dict
|
7 |
from urllib.error import HTTPError
|
8 |
|
|
|
45 |
history = []
|
46 |
messages = history_to_messages(history, system)
|
47 |
messages.append({'role': Role.USER, 'content': query})
|
48 |
+
|
49 |
+
generator = pipeline('text-generation', model='microsoft/Phi-3-mini-128k-instruct')
|
50 |
+
response = generator(query, max_length=150) # Ajusta la longitud máxima según necesidad
|
51 |
+
|
52 |
+
role = Role.ASSISTANT
|
53 |
+
response_content = response[0]['generated_text']
|
54 |
+
system, history = messages_to_history(messages + [{'role': role, 'content': response_content}])
|
55 |
+
return '', history, system
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
with gr.Blocks() as demo:
|
58 |
with gr.TabBar():
|