Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,10 +6,8 @@ from fastapi import FastAPI, HTTPException
|
|
6 |
from fastapi.middleware.cors import CORSMiddleware
|
7 |
import os
|
8 |
from dotenv import load_dotenv
|
9 |
-
import gradio as gr
|
10 |
-
import requests
|
11 |
-
import asyncio
|
12 |
from pydantic import BaseModel
|
|
|
13 |
|
14 |
load_dotenv()
|
15 |
HUGGINGFACE_TOKEN = os.getenv("HUGGINGFACE_TOKEN")
|
@@ -106,28 +104,6 @@ async def generate(request: ChatRequest):
|
|
106 |
|
107 |
return {"response": formatted_response}
|
108 |
|
109 |
-
async def process_message(message, history):
|
110 |
-
try:
|
111 |
-
port = int(os.environ.get("PORT", 7860))
|
112 |
-
response = requests.post(f"http://localhost:{port}/generate", json={"message": message}).json()
|
113 |
-
formatted_response = response["response"]
|
114 |
-
history.append((message, formatted_response))
|
115 |
-
return history, ""
|
116 |
-
except requests.exceptions.RequestException as e:
|
117 |
-
return history, f"Error communicating with the backend: {e}"
|
118 |
-
|
119 |
-
iface = gr.Interface(
|
120 |
-
fn=process_message,
|
121 |
-
inputs=[
|
122 |
-
gr.Textbox(lines=2, placeholder="Enter your message here..."),
|
123 |
-
gr.State([])
|
124 |
-
],
|
125 |
-
outputs=[gr.Chatbot(), gr.Textbox(visible=False)],
|
126 |
-
title="Multi-Model LLM API",
|
127 |
-
description="Enter a message and get responses from multiple LLMs.",
|
128 |
-
)
|
129 |
-
|
130 |
if __name__ == "__main__":
|
131 |
port = int(os.environ.get("PORT", 7860))
|
132 |
-
uvicorn.run(app, host="0.0.0.0", port=port)
|
133 |
-
iface.launch(server_port=7860)
|
|
|
6 |
from fastapi.middleware.cors import CORSMiddleware
|
7 |
import os
|
8 |
from dotenv import load_dotenv
|
|
|
|
|
|
|
9 |
from pydantic import BaseModel
|
10 |
+
import requests
|
11 |
|
12 |
load_dotenv()
|
13 |
HUGGINGFACE_TOKEN = os.getenv("HUGGINGFACE_TOKEN")
|
|
|
104 |
|
105 |
return {"response": formatted_response}
|
106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
if __name__ == "__main__":
|
108 |
port = int(os.environ.get("PORT", 7860))
|
109 |
+
uvicorn.run(app, host="0.0.0.0", port=port)
|
|