orama-ai commited on
Commit
84c97e6
·
verified ·
1 Parent(s): 99a6f62

Add app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ import urllib.request
4
+
5
+ def paraphrase_text(text, style):
6
+ if not text.strip():
7
+ return "Please enter some text to paraphrase."
8
+
9
+ try:
10
+ payload = json.dumps({
11
+ "model": "mistralai/mistral-7b-instruct",
12
+ "messages": [
13
+ {"role": "system", "content": f"You are a text paraphrasing expert. Paraphrase the given text in {style} style. Return ONLY the paraphrased text, nothing else."},
14
+ {"role": "user", "content": text}
15
+ ],
16
+ "max_tokens": 1024
17
+ }).encode()
18
+
19
+ req = urllib.request.Request(
20
+ "https://openrouter.ai/api/v1/chat/completions",
21
+ data=payload,
22
+ headers={
23
+ "Content-Type": "application/json",
24
+ "Authorization": "Bearer sk-or-v1-placeholder"
25
+ }
26
+ )
27
+
28
+ with urllib.request.urlopen(req, timeout=30) as response:
29
+ result = json.loads(response.read())
30
+ return result["choices"][0]["message"]["content"]
31
+ except Exception as e:
32
+ return f"Error: {str(e)}"
33
+
34
+ demo = gr.Interface(
35
+ fn=paraphrase_text,
36
+ inputs=[
37
+ gr.Textbox(label="Enter your text", lines=5, placeholder="Paste text here..."),
38
+ gr.Dropdown(
39
+ choices=["Professional", "Casual", "Academic", "Creative", "Simple", "Formal"],
40
+ label="Paraphrase Style",
41
+ value="Professional"
42
+ )
43
+ ],
44
+ outputs=gr.Textbox(label="Paraphrased Text", lines=5),
45
+ title="AI Paraphrase Pro",
46
+ description="Instantly paraphrase any text in multiple styles. Powered by AI.",
47
+ examples=[
48
+ ["The quick brown fox jumps over the lazy dog.", "Creative"],
49
+ ["I think that we should consider the implications of this decision carefully.", "Simple"],
50
+ ]
51
+ )
52
+
53
+ if __name__ == "__main__":
54
+ demo.launch()
55
+