Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
try:
|
7 |
-
# 模拟 API 请求(替换为实际逻辑)
|
8 |
-
response = requests.post("http://127.0.0.1:7860/api/query", json={"query": query})
|
9 |
-
if response.status_code != 200:
|
10 |
-
return f"Error: Server returned status code {response.status_code}"
|
11 |
-
|
12 |
-
response_data = response.json()
|
13 |
-
return response_data.get("answer", "No answer found in response.")
|
14 |
-
except Exception as e:
|
15 |
-
return f"Error: {str(e)}"
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
fn=get_ollama_response, # 输入输出处理函数
|
20 |
-
inputs="text", # 输入为文本
|
21 |
-
outputs="text", # 输出为文本
|
22 |
-
title="Hugging Face Gradio App",
|
23 |
-
)
|
24 |
|
25 |
-
#
|
26 |
-
iface.
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
# 加载 CodeGen 模型
|
5 |
+
code_generator = pipeline('text-generation', model='Salesforce/codegen-350M-multi')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
def generate_code(prompt):
|
8 |
+
return code_generator(prompt, max_length=100)[0]['generated_text']
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
+
# 创建 Gradio 接口
|
11 |
+
iface = gr.Interface(fn=generate_code, inputs="text", outputs="text")
|
12 |
+
iface.launch()
|