Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import AutoTokenizer
|
| 3 |
from optimum.intel import OVModelForCausalLM
|
|
|
|
|
|
|
|
|
|
| 4 |
import warnings
|
| 5 |
warnings.filterwarnings("ignore", category=DeprecationWarning, message="__array__ implementation doesn't accept a copy keyword")
|
| 6 |
|
|
@@ -50,20 +53,19 @@ with gr.Blocks() as demo:
|
|
| 50 |
description="回傳輸入內容的測試 API",
|
| 51 |
)
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
inputs=gr.Textbox(label="Prompt"),
|
| 60 |
-
outputs="text",
|
| 61 |
-
api_name="/maxtest",
|
| 62 |
-
title="MaxTest API",
|
| 63 |
-
description="回傳輸入內容的測試 API",
|
| 64 |
-
visible=False
|
| 65 |
-
)
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
if __name__ == "__main__":
|
| 69 |
print("Launching Gradio app...")
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import AutoTokenizer
|
| 3 |
from optimum.intel import OVModelForCausalLM
|
| 4 |
+
from fastapi import FastAPI
|
| 5 |
+
import uvicorn
|
| 6 |
+
from pydantic import BaseModel
|
| 7 |
import warnings
|
| 8 |
warnings.filterwarnings("ignore", category=DeprecationWarning, message="__array__ implementation doesn't accept a copy keyword")
|
| 9 |
|
|
|
|
| 53 |
description="回傳輸入內容的測試 API",
|
| 54 |
)
|
| 55 |
|
| 56 |
+
|
| 57 |
+
app = FastAPI()
|
| 58 |
+
class Prompt(BaseModel):
|
| 59 |
+
prompt: str
|
| 60 |
|
| 61 |
+
def maxtest(prompt: str) -> str:
|
| 62 |
+
# 在此处实现您的逻辑
|
| 63 |
+
return f"您输入的内容是: {prompt}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
+
@app.post("/maxtest")
|
| 66 |
+
async def call_maxtest(prompt: Prompt):
|
| 67 |
+
response = maxtest(prompt.prompt)
|
| 68 |
+
return {"response": response}
|
| 69 |
|
| 70 |
if __name__ == "__main__":
|
| 71 |
print("Launching Gradio app...")
|