Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ from huggingface_hub import InferenceClient, HfApi
|
|
3 |
import os
|
4 |
import requests
|
5 |
import pandas as pd
|
|
|
6 |
|
7 |
# Hugging Face ν ν° νμΈ
|
8 |
hf_token = os.getenv("HF_TOKEN")
|
@@ -35,6 +36,8 @@ def get_prompt(act):
|
|
35 |
matching_prompt = prompts_df[prompts_df['act'] == act]['prompt'].values
|
36 |
return matching_prompt[0] if len(matching_prompt) > 0 else None
|
37 |
|
|
|
|
|
38 |
def respond(
|
39 |
message,
|
40 |
history: list[tuple[str, str]],
|
@@ -68,32 +71,37 @@ def respond(
|
|
68 |
|
69 |
def query(payload):
|
70 |
response = requests.post(API_URL, headers=headers, json=payload)
|
71 |
-
return response.
|
72 |
|
73 |
try:
|
74 |
-
|
75 |
"inputs": messages,
|
76 |
"parameters": {
|
77 |
"max_new_tokens": max_tokens,
|
78 |
"temperature": temperature,
|
79 |
"top_p": top_p,
|
80 |
-
"stream":
|
81 |
},
|
82 |
-
}
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
|
|
90 |
|
91 |
except Exception as e:
|
92 |
print(f"Error during API request: {e}")
|
93 |
-
|
|
|
|
|
94 |
|
95 |
-
|
96 |
-
yield "μ£μ‘ν©λλ€. μλ΅μ μμ±νμ§ λͺ»νμ΅λλ€."
|
97 |
|
98 |
demo = gr.ChatInterface(
|
99 |
respond,
|
|
|
3 |
import os
|
4 |
import requests
|
5 |
import pandas as pd
|
6 |
+
import json
|
7 |
|
8 |
# Hugging Face ν ν° νμΈ
|
9 |
hf_token = os.getenv("HF_TOKEN")
|
|
|
36 |
matching_prompt = prompts_df[prompts_df['act'] == act]['prompt'].values
|
37 |
return matching_prompt[0] if len(matching_prompt) > 0 else None
|
38 |
|
39 |
+
|
40 |
+
|
41 |
def respond(
|
42 |
message,
|
43 |
history: list[tuple[str, str]],
|
|
|
71 |
|
72 |
def query(payload):
|
73 |
response = requests.post(API_URL, headers=headers, json=payload)
|
74 |
+
return response.text # μμ μλ΅ ν
μ€νΈ λ°ν
|
75 |
|
76 |
try:
|
77 |
+
payload = {
|
78 |
"inputs": messages,
|
79 |
"parameters": {
|
80 |
"max_new_tokens": max_tokens,
|
81 |
"temperature": temperature,
|
82 |
"top_p": top_p,
|
83 |
+
"stream": False # μ€νΈλ¦¬λ°μ λΉνμ±ν
|
84 |
},
|
85 |
+
}
|
86 |
+
raw_response = query(payload)
|
87 |
+
print("Raw API response:", raw_response) # λλ²κΉ
μ μν΄ μμ μλ΅ μΆλ ₯
|
88 |
+
|
89 |
+
try:
|
90 |
+
output = json.loads(raw_response)
|
91 |
+
if isinstance(output, list) and len(output) > 0 and "generated_text" in output[0]:
|
92 |
+
response = output[0]["generated_text"]
|
93 |
+
else:
|
94 |
+
response = f"μμμΉ λͺ»ν μλ΅ νμμ
λλ€: {output}"
|
95 |
+
except json.JSONDecodeError:
|
96 |
+
response = f"JSON λμ½λ© μ€λ₯. μμ μλ΅: {raw_response}"
|
97 |
|
98 |
except Exception as e:
|
99 |
print(f"Error during API request: {e}")
|
100 |
+
response = f"μ£μ‘ν©λλ€. μλ΅ μμ± μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}"
|
101 |
+
|
102 |
+
yield response
|
103 |
|
104 |
+
# λλ¨Έμ§ μ½λλ κ·Έλλ‘ μ μ§
|
|
|
105 |
|
106 |
demo = gr.ChatInterface(
|
107 |
respond,
|