Spaces:
Running
Running
File size: 1,381 Bytes
30072fc 0e0988e 30072fc a1e4ce1 30072fc f8eb332 30072fc 8651ac0 30072fc f8eb332 0e0988e f8eb332 0e0988e f8eb332 30072fc fb6683e ea1ae77 30072fc f8eb332 30072fc 7c48783 |
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 42 43 44 45 46 47 |
import gradio as gr
import requests
import os
import json
# ACCESS_TOKEN = os.getenv("HF_TOKEN")
def respond(message, history, max_tokens=512, temperature=0.7, top_p=0.95):
data = {
"model": "jinjavis:latest",
"prompt": message,
"max_tokens": max_tokens,
"temperature": temperature,
"top_p": top_p
}
# API 요청
response = requests.post("http://hugpu.ai:7877/api/generate", json=data, stream=True)
partial_message = ""
for line in response.iter_lines():
if line:
try:
result = json.loads(line)
if result.get("done", False):
break
new_text = result.get('response', '')
partial_message += new_text
yield partial_message
except json.JSONDecodeError as e:
print(f"Failed to decode JSON: {e}")
yield "An error occurred while processing your request."
demo = gr.ChatInterface(
fn=respond,
additional_inputs=[
gr.Slider(minimum=1, maximum=2048, value=512, label="Max Tokens"),
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, label="Temperature"),
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, label="Top-P")
],
theme="Nymbo/Nymbo_Theme"
)
if __name__ == "__main__":
demo.queue(max_size=10).launch() |