import gradio as gr
from textblob import TextBlob
import requests
def call_api(text: str):
"""
Call the API with the given text.
Args:
text (str): The text as input
Returns:
json: the response in json format
"""
api_url = "http://localhost:11434/v1/chat/completions" # Replace with your API URL
headers = {"Content-Type": "application/json"}
payload = {"model": "granite3.2:8b","messages": [{"role": "users", "content": text }]}
try:
response = requests.post(api_url, headers=headers, json=payload)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
data = response.json() # Assuming the API returns JSON
return data
except requests.exceptions.RequestException as e:
return f"Error calling API: {e}"
# Create the Gradio interface
demo = gr.Interface(
fn=call_api,
inputs=gr.Textbox(placeholder="Enter text as input..."),
outputs=gr.JSON(),
title="Call API",
description="Call the api using Text as input"
)
# Launch the interface and MCP server
if __name__ == "__main__":
demo.launch(mcp_server=True)