Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,9 +2,8 @@ import os
|
|
2 |
import gradio as gr
|
3 |
import aiohttp
|
4 |
import asyncio
|
5 |
-
import requests
|
6 |
-
import mimetypes
|
7 |
import json
|
|
|
8 |
|
9 |
LLM_API = os.environ.get("LLM_API")
|
10 |
LLM_URL = os.environ.get("LLM_URL")
|
@@ -43,7 +42,8 @@ async def send_chat_message(LLM_URL, LLM_API, user_input):
|
|
43 |
print("Received line:", line) # Debug information
|
44 |
data = json.loads(line.split("data: ")[1])
|
45 |
if "answer" in data:
|
46 |
-
|
|
|
47 |
except (IndexError, json.JSONDecodeError) as e:
|
48 |
print(f"Error parsing line: {line}, error: {e}") # Debug information
|
49 |
continue
|
@@ -53,7 +53,7 @@ async def send_chat_message(LLM_URL, LLM_API, user_input):
|
|
53 |
else:
|
54 |
return "Error: No response found in the response"
|
55 |
except Exception as e:
|
56 |
-
print(f"Exception: {e}")
|
57 |
return f"Exception: {e}"
|
58 |
|
59 |
async def handle_input(user_input):
|
@@ -73,13 +73,16 @@ def run_sync(func, *args):
|
|
73 |
user_input = gr.Textbox(label='請輸入您想查詢的關鍵公司名稱')
|
74 |
examples = [
|
75 |
["加密貨幣"],
|
76 |
-
["國泰金控"],
|
77 |
["中華電信"],
|
78 |
-
["台灣大哥大"],
|
79 |
["台積電"],
|
80 |
-
["BlockTempo"]
|
81 |
]
|
82 |
|
|
|
|
|
|
|
83 |
TITLE = """<h1>Social Media Trends 💬 分析社群相關資訊,並判斷其正、負、中立等評價及趨勢 </h1>"""
|
84 |
SUBTITLE = """<h2><a href='https://www.twman.org' target='_blank'>TonTon Huang Ph.D. @ 2024/11 </a><br></h2>"""
|
85 |
LINKS = """
|
@@ -98,7 +101,7 @@ with gr.Blocks() as iface:
|
|
98 |
gr.HTML(SUBTITLE)
|
99 |
gr.HTML(LINKS)
|
100 |
gr.Interface(
|
101 |
-
fn=lambda x: run_sync(handle_input, x),
|
102 |
inputs=user_input,
|
103 |
outputs="text",
|
104 |
examples=examples,
|
|
|
2 |
import gradio as gr
|
3 |
import aiohttp
|
4 |
import asyncio
|
|
|
|
|
5 |
import json
|
6 |
+
import urllib.parse
|
7 |
|
8 |
LLM_API = os.environ.get("LLM_API")
|
9 |
LLM_URL = os.environ.get("LLM_URL")
|
|
|
42 |
print("Received line:", line) # Debug information
|
43 |
data = json.loads(line.split("data: ")[1])
|
44 |
if "answer" in data:
|
45 |
+
decoded_answer = urllib.parse.unquote(data["answer"])
|
46 |
+
full_response.append(decoded_answer)
|
47 |
except (IndexError, json.JSONDecodeError) as e:
|
48 |
print(f"Error parsing line: {line}, error: {e}") # Debug information
|
49 |
continue
|
|
|
53 |
else:
|
54 |
return "Error: No response found in the response"
|
55 |
except Exception as e:
|
56 |
+
print(f"Exception occurred in send_chat_message: {e}")
|
57 |
return f"Exception: {e}"
|
58 |
|
59 |
async def handle_input(user_input):
|
|
|
73 |
user_input = gr.Textbox(label='請輸入您想查詢的關鍵公司名稱')
|
74 |
examples = [
|
75 |
["加密貨幣"],
|
76 |
+
# ["國泰金控"],
|
77 |
["中華電信"],
|
78 |
+
# ["台灣大哥大"],
|
79 |
["台積電"],
|
80 |
+
# ["BlockTempo"]
|
81 |
]
|
82 |
|
83 |
+
|
84 |
+
|
85 |
+
|
86 |
TITLE = """<h1>Social Media Trends 💬 分析社群相關資訊,並判斷其正、負、中立等評價及趨勢 </h1>"""
|
87 |
SUBTITLE = """<h2><a href='https://www.twman.org' target='_blank'>TonTon Huang Ph.D. @ 2024/11 </a><br></h2>"""
|
88 |
LINKS = """
|
|
|
101 |
gr.HTML(SUBTITLE)
|
102 |
gr.HTML(LINKS)
|
103 |
gr.Interface(
|
104 |
+
fn=lambda x: run_sync(handle_input, x),
|
105 |
inputs=user_input,
|
106 |
outputs="text",
|
107 |
examples=examples,
|