Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from openai import OpenAI
|
| 3 |
+
|
| 4 |
+
BASE_URL = "https://w0xtwbf2fdxe1q-8000.proxy.runpod.net/v1"
|
| 5 |
+
API_KEY="SOMEHOW"
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
# Create an OpenAI client to interact with the API server
|
| 9 |
+
client = OpenAI(
|
| 10 |
+
base_url=BASE_URL,
|
| 11 |
+
api_key=API_KEY
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def predict(message, history):
|
| 16 |
+
# Convert chat history to OpenAI format
|
| 17 |
+
history_openai_format = [{
|
| 18 |
+
"role": "system",
|
| 19 |
+
"content": "Tu es un excellent assistant IA développé par WAY2CALL pour faire des évaluations en JSON des audios transcrits."
|
| 20 |
+
}]
|
| 21 |
+
for human, assistant in history:
|
| 22 |
+
history_openai_format.append({"role": "user", "content": human})
|
| 23 |
+
history_openai_format.append({
|
| 24 |
+
"role": "assistant",
|
| 25 |
+
"content": assistant
|
| 26 |
+
})
|
| 27 |
+
history_openai_format.append({"role": "user", "content": message})
|
| 28 |
+
|
| 29 |
+
# Create a chat completion request and send it to the API server
|
| 30 |
+
stream = client.chat.completions.create(
|
| 31 |
+
model="CONCREE/meta-adia-llm-instruct", # Model name to use
|
| 32 |
+
messages=history_openai_format, # Chat history
|
| 33 |
+
temperature=0.1, # Temperature for text generation
|
| 34 |
+
stream=True, # Stream response
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# Read and return generated text from response stream
|
| 38 |
+
partial_message = ""
|
| 39 |
+
for chunk in stream:
|
| 40 |
+
partial_message += (chunk.choices[0].delta.content or "")
|
| 41 |
+
yield partial_message
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
# Create and launch a chat interface with Gradio
|
| 45 |
+
gr.ChatInterface(predict).queue().launch()
|