Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from gradio_client import Client
|
| 3 |
+
|
| 4 |
+
# This client connects to a language model that can write text
|
| 5 |
+
llm_client = Client("hysts/zephyr-7b")
|
| 6 |
+
|
| 7 |
+
def create_compliment(text_description: str) -> str:
|
| 8 |
+
"""
|
| 9 |
+
Takes a text description of a scene and turns it into a fun, friendly compliment.
|
| 10 |
+
|
| 11 |
+
Args:
|
| 12 |
+
text_description: A description of what is in a picture.
|
| 13 |
+
"""
|
| 14 |
+
prompt = f"Please turn the following description into a short, fun, and friendly compliment: {text_description}"
|
| 15 |
+
|
| 16 |
+
# We send the prompt to the language model to get our final result.
|
| 17 |
+
compliment = llm_client.predict(
|
| 18 |
+
prompt=prompt,
|
| 19 |
+
max_new_tokens=128,
|
| 20 |
+
api_name="/add_text"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
return compliment
|
| 24 |
+
|
| 25 |
+
# Create the Gradio interface
|
| 26 |
+
iface = gr.Interface(
|
| 27 |
+
fn=create_compliment,
|
| 28 |
+
inputs=gr.Textbox(label="Describe a scene or person"),
|
| 29 |
+
outputs=gr.Textbox(label="Generated Compliment"),
|
| 30 |
+
title="The Complimenter Tool",
|
| 31 |
+
description="An MCP server that generates compliments from text descriptions. [1, 2]"
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
# Launch the app as an MCP server
|
| 35 |
+
if __name__ == "__main__":
|
| 36 |
+
iface.launch(mcp_server=True)
|