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